<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>任务管理</title>
		<script type="text/javascript" language="JavaScript" src="../script/common.js"></script>
		<script type="text/javascript" language="JavaScript" src="../script/tree.js"></script>
		<script type="text/javascript" language="JavaScript">
			var tree;
			var qt = {};
			var org = Common.cOrg();
			var openIcon = "../images/tree/root.png";
			var icon = "../images/tree/root.png";
			
			
			function load() {
			    Eui.showNavigation();
			    writeTree();
			}
			/**树**/
			function writeTree() {
			    webTreeHandler.init();
			    tree = new LoadTree("系统任务", null, "javascript:showRoot()", null, "../images/tree/root.png", "../images/tree/root.png");
			    $("acltree").innerHTML = tree;
			    tree.select();
			    showRoot();
			}
			
			function showRoot() {
			    $('taskinfo').style.display = "none";
			}
			
			function _startLoadXmlTree(sSrc, jsNode, newNode) {
			    DWR.call("taskService.getTasks", function(result) {
			        _xmlFileLoaded(result, jsNode);
			    });
			}
			
			function _createNode(obj) {
			    if (obj.action) {
			        node = createTreeNode(true, obj.name, obj.code, "javascript:showProperty()");
			    } else
			        node = createTreeNode(true, "新任务", null, "javascript:showProperty()");
			    node.obj = obj;
			    return node;
			}
			var taskAction = null;
			function showProperty() {
			    var node = tree.getSelected();
			    var obj = node.obj;
			    if (obj.code)
			        formDisable(true);
			    else
			        formDisable(false);
			    $('taskinfo').style.display = "";
			    taskDefForm.reset();
			    if (obj.code) {
			        DWR.call("taskService.getTask", obj.code, function(task) {
			           	node.obj = task;
			           	Common.setValues(taskDefForm, task);
			            
			        })
			    }
			}
			//设置保存，取消，启动，停止按钮的状态
			function formDisable(status) {
			    taskDefForm.name.disabled = status;
			    taskDefForm.action.disabled = status;
			    taskDefForm.time.disabled = status;
			    taskDefForm.day.disabled = status;
			    taskDefForm.period.disabled = status;
			    taskDefForm.enabled.disabled = status;
			
			    taskDefForm.edittaskbt.disabled = !status;
			    taskDefForm.savetaskbt.disabled = status;
			    taskDefForm.canceltaskbt.disabled = status;
			    taskDefForm.starttaskbt.disabled = !status;
			    taskDefForm.stoptaskbt.disabled = !status;
			}
			
			//保存系统任务设置
			function saveTask() {
			    if (!checkForm(taskDefForm)) return;
			    var treeNode = tree.getSelected();
			    var taskDef = Common.getValues(taskDefForm);
			    DWR.call("taskService.saveTask", taskDef, function() {
			        showInformation("任务【" + taskDef.name + "】保存成功");
			        if (treeNode) {
			            treeNode.obj = taskDef;
			            treeNode.setText(taskDef.name);
			            treeNode.src = taskDef.code;
			        }
			        showProperty();
			    },{disCtrl:$('savetaskbt')});
			}
			//启动系统任务
			function startTask() {
			    var node = tree.getSelected();
			    if (!node || !node.obj) {
			        showWarning("请选择一个任务");
			        return;
			    }
			    DWR.call("taskService.startTask", node.src, function() {
			        showInformation("服务 " + node.obj.name + " 启动成功");
			    },{disCtrl:taskDefForm.starttaskbt})
			}
			//停止系统任务
			function stopTask() {
			    var node = tree.getSelected();
			    if (!node || !node.obj) {
			        showWarning("请选择一个任务");
			        return;
			    }
			    DWR.call("taskService.stopTask", node.src, function() {
			        showInformation("服务 " + node.obj.name + " 已停止");
			    },{disCtrl:$('stoptaskbt')})
			}
			
			//取消编辑或者新增
			function onCancel() {
			    var node = tree.getSelected()
			    if (!node.obj.id) {
			        node.remove();
			    }
			    showProperty();
				CardMgnt.resetForm(taskDefForm)
			}
		</script>
	</head>
	
	<body onload="load()">
		            <div class="nav">
		                <div id="nav">&nbsp;</div>
		            </div>
		<table cellSpacing="0" cellPadding="0" width="100%" border="0" class="treeFrame">
		    <tr>
		        <td valign="top" height="100%" width="30%">
		            <div id="acltree" class="scrollDiv treeDiv"></div>
		        </td>
		        <td width="60%" valign="top" height="100%">
		            <div id="treeDet" class="scrollDiv pad5">
		                <div id="taskinfo">
		                    <form id="taskDefForm" name="taskDefForm">
		                        <input type="hidden" name="id">
		
		                        <div class="form">
		                            <div class="formTitle">任务详细信息</div>
		                            <table cellSpacing="0" cellPadding="4" width="100%" border="0">
		                                <tr>
		                                    <td align="center"><label>任务名称</label></td>
		                                    <td><input name="name" type="text" disabled maxlength="100"></td>
		                                </tr>
		                                <tr>
		                                    <td align="center"><label>任务标识</label></td>
		                                    <td><input name="code" type="text" disabled maxlength="100"></td>
		                                </tr>
		                                <tr>
		                                    <td align="center"><label>后台方法</label></td>
		                                    <td><input name="action" type="text" disabled maxlength="100"></td>
		                                </tr>
		                                <tr>
		                                    <td align="center"><label>运行时间</label></td>
		                                    <td><input name="time" type="text" disabled  maxlength="40"></td>
		                                </tr>
		                                <tr>
		                                    <td align="center"><label>运行日期</label></td>
		                                    <td><input name="day" type="text" disabled maxlength="20"></td>
		                                </tr>
		                                <tr>
		                                    <td align="center"><label>运行周期</label></td>
		                                    <td><input name="period" type="text" disabled onblur="checkV(this,'number')" maxlength="10"></td>
		                                </tr>
		                                <tr>
		                                    <td align="center"><label>自动运行</label></td>
		                                    <td><input name="enabled" type="text" disabled ></td>
		                                </tr>
		                            </table>
		                        </div>
		                        <div align="center">
									<button type="button" name="edittaskbt" onclick="formDisable(false)">编 辑</button>
									<button type="button" name="savetaskbt" onclick="saveTask()" disabled>保 存</button>
									<button type="button" name="canceltaskbt" onclick="onCancel()" disabled>取 消</button>
								</div>
		                        <div align="center">
									<button type="button" name="starttaskbt" onclick="startTask()">启 动</button>
									<button type="button" name="stoptaskbt" onclick="stopTask()">停 止</button>
								</div>
		                    </form>
		                </div>
		            </div>
		        </td>
		    </tr>
		</table>
	</body>
</html>